package com.opennetexam.manager.sqlprovider;

import com.opennetexam.manager.dto.ExamineeExamPaperItem;
import com.opennetexam.manager.utils.GsonUtil;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 奶茶
 * Created by on 2017/12/7.
 */
public class ExamineeExamPaperItemProvider {

    private static final Logger logger = Logger.getLogger(ExamineeExamPaperItemProvider.class);

    public String deleteExamineeExamPaperItems(Map<String,Object> parameter){
        StringBuilder sb = new StringBuilder("");
        sb.append("DELETE FROM ExamineeExamPaperItem WHERE 1=1 AND ");
        List<ExamineeExamPaperItem> items = GsonUtil.fromJsonToList(GsonUtil.toJson(parameter.get("items")), ExamineeExamPaperItem.class);
        for (int i=0;i<items.size();i++){
            if(i != (items.size()-1)){
                sb.append("(ExamPaperInfoID = \'").append(items.get(i).getExamPaperInfoID()).append("\' AND PaperID = \'").append(items.get(i).getPaperID()).append("\' AND ItemID = \'").append(items.get(i).getItemID()).append("\') OR ");
            }else{
                sb.append("(ExamPaperInfoID = \'").append(items.get(i).getExamPaperInfoID()).append("\' AND PaperID = \'").append(items.get(i).getPaperID()).append("\' AND ItemID = \'").append(items.get(i).getItemID()).append("\') ");
            }
        }

        String sql = sb.toString();
        logger.info(sql);
        return sql;
    }


    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<>();
        List<ExamineeExamPaperItem> examineeExamPaperItems = new ArrayList<>();
        ExamineeExamPaperItem paperItem = new ExamineeExamPaperItem();
        paperItem.setExamPaperInfoID("1");
        paperItem.setPaperID("1");
        paperItem.setItemID("1");

        examineeExamPaperItems.add(paperItem);
        examineeExamPaperItems.add(paperItem);

        map.put("items",examineeExamPaperItems);

//        deleteExamineeExamPaperItems(map);

    }
}
